package wiki.xsx.config;

import java.util.Arrays;
import java.util.List;

/**
 * @Descript
 * @Author xsx
 * @Date 2018/1/17
 */
public class Config {
    private DataSource dataSource;
    private List<TargetDataSource> targetDataSources;

    private Long period;
    private boolean isErrorContinue;

    public Config(DataSource dataSource, TargetDataSource... targetDataSource) {
        this.dataSource = dataSource;
        this.targetDataSources = Arrays.asList(targetDataSource);
    }

    public Config(DataSource dataSource, Long period, TargetDataSource... targetDataSource) {
        this.dataSource = dataSource;
        this.period = period;
        this.targetDataSources = Arrays.asList(targetDataSource);
    }

    public Config(DataSource dataSource, List<TargetDataSource> targetDataSources) {
        this.dataSource = dataSource;
        this.targetDataSources = targetDataSources;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public List<TargetDataSource> getTargetDataSources() {
        return targetDataSources;
    }

    public void setTargetDataSources(List<TargetDataSource> targetDataSources) {
        this.targetDataSources = targetDataSources;
    }

    public Long getPeriod() {
        return period;
    }

    public void setPeriod(TimeType timeType, Integer period) {
        switch (timeType){
            case DAYS:
                this.period = TimeType.DAYS.toSeconds(period);
                break;
            case HOURS:
                this.period = TimeType.HOURS.toSeconds(period);
                break;
            case MINUTES:
                this.period = TimeType.MINUTES.toSeconds(period);
                break;
            default:
                throw new RuntimeException("the type of TimeUnit must be 'DAYS','HOURS' or 'MINUTES'");
        }
    }

    public boolean isErrorContinue() {
        return isErrorContinue;
    }

    public void setErrorContinue(boolean errorContinue) {
        isErrorContinue = errorContinue;
    }
}
